Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static public string ForceJson(object res)
- {
- JavaScriptSerializer js = new JavaScriptSerializer();
- return ( js.Serialize(res) );
- }
- static public byte[] Hash(string plainString, Encoding encoding)
- {
- if (plainString == null)
- throw new ArgumentNullException("plainString");
- if (encoding == null)
- encoding = Encoding.UTF8;
- return Hash(encoding.GetBytes(plainString));
- }
- static public byte[] Hash(byte[] bytes)
- {
- if (bytes == null)
- throw new ArgumentNullException("bytes");
- using (SHA256 algorithm = new SHA256Managed())
- {
- byte[] hashBytes = algorithm.ComputeHash(bytes);
- return hashBytes;
- }
- }
- public string HashToBase64(string plainString, Encoding encoding)
- {
- if (plainString == null) throw new ArgumentNullException("plainString");
- return Convert.ToBase64String(Hash(plainString, encoding));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement